package com.mxsat.system.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mxsat.common.annotation.ResponseResult;
import com.mxsat.common.result.PlatformResult;
import com.mxsat.system.entity.SysDict;
import com.mxsat.system.entity.SysDictItem;
import com.mxsat.system.service.SysDictionaryService;

@ResponseResult(PlatformResult.class)
@RestController
@RequestMapping("/*")
public class SystemDictionaryController {

	@Autowired
	private SysDictionaryService sysDictionaryService;
	
	@GetMapping("/dicts")
	public Page<SysDict> dicts() throws Exception {
		Page<SysDict> page = new Page<>();
		return (Page<SysDict>) sysDictionaryService.findSysDictByPage(page);
	}
	
	@PostMapping("/dict")
	public  boolean addDict(SysDict dict) throws Exception {
		return sysDictionaryService.addSysDict(dict);
	}
	
	@PutMapping("/dict")
	public  boolean modifyDict(SysDict dict) throws Exception {
		return sysDictionaryService.modfiySysDict(dict);
	}
	@DeleteMapping("/dict/{code}")
	public boolean removeDict(@PathVariable String code) throws Exception {
		return sysDictionaryService.removeSysDict(code);
	}
	
	@GetMapping("/dictitems/{code}")
	public Page<SysDictItem> dictitems(@PathVariable String code) throws Exception {
		Page<SysDictItem> page = new Page<>();
		return (Page<SysDictItem>) sysDictionaryService.findSysDictItemByPage(page,code);
	}
	
	@PostMapping("/dictitem")
	public boolean addDictitem(SysDictItem item) throws Exception {
		item.setData_status("N");
		return sysDictionaryService.addSysDictItem(item);
	}
	
	@PutMapping("/dictitem")
	public boolean modfiyDictitem(SysDictItem item) throws Exception {
		return sysDictionaryService.modifySysDictItem(item);
	}
	
	@DeleteMapping("/dictitem/{id}")
	public boolean removeDictitem(@PathVariable Long id) throws Exception {
		return sysDictionaryService.removeSysDictItem(id);
	}
}
